//
//  UIButton+Extension.swift
//  weibo
//
//  Created by 谭仁川 on 15/12/1.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

extension UIButton {

    convenience init(title: String,backImage:String? ,color: UIColor,fontSize: CGFloat,isNeedHightlighted: Bool = false,imageName: String? = nil){
        self.init()
        setTitle(title, forState: .Normal)
        
        if backImage != nil {
            setBackgroundImage(UIImage(named: backImage!), forState: .Normal)
       
        if isNeedHightlighted {
            setBackgroundImage(UIImage(named: backImage! + "highlighted"), forState: .Normal)
          }
            
        }
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
    
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    
        sizeToFit()
        
        
  
    }
    convenience init(imageName: String,backImage:String){
        self.init()
        
        setBackgroundImage(UIImage(named: backImage), forState: .Normal)
         setBackgroundImage(UIImage(named: backImage + "_highlighted"), forState: .Highlighted)
        
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        sizeToFit()
        
        
        
    }

}
